#!/usr/bin/env tclsh
source streamtestlib.tcl

# Define records, protocol and startup (text goes to files)
# The asynPort "device" is connected to a network TCP socket
# Talk to the socket with send/receive/assure
# Send commands to the ioc shell with ioccmd

set records {
    record (bo, "DZ:percent")
    {
        field (DTYP, "stream")
        field (OUT,  "@test.proto percent device")
    }
    record (ao, "DZ:ao")
    {
        field (DTYP, "stream")
        field (OUT,  "@test.proto ao device")
        field (EOFF, "-10")
        field (ESLO, "0.000305180437934")
        field (LINR, "LINEAR")
    }
    record (longout, "DZ:lo")
    {
        field (DTYP, "stream")
        field (OUT,  "@test.proto lo device")
    }
    record (longout, "DZ:bcd")
    {
        field (DTYP, "stream")
        field (OUT,  "@test.proto bcd device")
    }
    record (longout, "DZ:sbcd")
    {
        field (DTYP, "stream")
        field (OUT,  "@test.proto sbcd device")
    }
}

set protocol {
    Terminator = LF;
    percent {out "\%\x25\37\045" 0x25 37 045;}
    ao {out "%.2f %.2e %.2E %.2g %.2G %i %d %u %o %04x %#.2f %#.2e %#.2E %#.2g %#.2G %#i %#d %#u %#o %#06x";}
    lo {out "%d %(VAL)d %06d %x %06X %b %06b %.6b %B.! %06B.!";}
    bcd {out "%D %6D %.2D %.3D %.6D %.8D %#D %#6D %#.2D %#.3D %#.6D";}
    sbcd {out "%+D %+6D %+.2D %+.3D %+.6D %+.8D %+#D %+#6D %+#.2D %#+.3D %#+.6D";}
}

set startup {
}

set debug 0

startioc

# Some formats give different results on 32 bit and 64 bit machines.
# Specify the width field in the format if this is a problem.

put DZ:percent 1
assure "%%%%%%%\n"
put DZ:ao 0
assure "0.00 0.00e+00 0.00E+00 0 0 32767 32767 32767 77777 7fff 0.00 0.00e+00 0.00E+00 0.0 0.0 32767 32767 32767 077777 0x7fff\n"
put DZ:ao 10
assure "10.00 1.00e+01 1.00E+01 10 10 65535 65535 65535 177777 ffff 10.00 1.00e+01 1.00E+01 10. 10. 65535 65535 65535 0177777 0xffff\n"
put DZ:ao -10
assure "-10.00 -1.00e+01 -1.00E+01 -10 -10 0 0 0 0 0000 -10.00 -1.00e+01 -1.00E+01 -10. -10. 0 0 0 0 000000\n"
put DZ:ao 1e-6
assure "0.00 1.00e-06 1.00E-06 1e-06 1E-06 32768 32768 32768 100000 8000 0.00 1.00e-06 1.00E-06 1.0e-06 1.0E-06 32768 32768 32768 0100000 0x8000\n"
put DZ:lo 0
assure "0 0 000000 0 000000 0 000000 000000 . ......\n"
put DZ:lo 12345
assure "12345 12345 012345 3039 003039 11000000111001 11000000111001 111001 !!......!!!..! !!......!!!..!\n"
put DZ:lo 2147483647
assure "2147483647 2147483647 2147483647 7fffffff FFFFFF 1111111111111111111111111111111 1111111111111111111111111111111 111111 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
put DZ:lo -1
assure "-1 -1 -00001 ffffffff FFFFFF 11111111111111111111111111111111 11111111111111111111111111111111 111111 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
put DZ:lo -1234
assure "-1234 -1234 -01234 fffffb2e FFFB2E 11111111111111111111101100101110 11111111111111111111101100101110 101110 !!!!!!!!!!!!!!!!!!!!!.!!..!.!!!. !!!!!!!!!!!!!!!!!!!!!.!!..!.!!!.\n"
put DZ:lo 255
assure "255 255 000255 ff 0000FF 11111111 11111111 111111 !!!!!!!! !!!!!!!!\n"
put DZ:lo 65535
assure "65535 65535 065535 ffff 00FFFF 1111111111111111 1111111111111111 111111 !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!\n"
put DZ:bcd 1020304
if {$tcl_platform(machine) == "x86_64"} {
assure "\0\0\0\0\1\2\3\4 \0\0\0\0\1\2\3\4 \4 \3\4 \2\3\4 \1\2\3\4 \4\3\2\1\0\0\0\0 \4\3\2\1\0\0\0\0 \4 \4\3 \4\3\2\n"
} else {
assure "\1\2\3\4 \0\0\1\2\3\4 \4 \3\4 \2\3\4 \1\2\3\4 \4\3\2\1 \4\3\2\1\0\0 \4 \4\3 \4\3\2\n"
}
put DZ:sbcd 1020304
if {$tcl_platform(machine) == "x86_64"} {
assure "\0\0\0\0\0\1\2\3\4 \0\0\0\0\0\1\2\3\4 \0\4 \3\4 \0\2\3\4 \0\1\2\3\4 \4\3\2\1\0\0\0\0\0 \4\3\2\1\0\0\0\0\0 \4\0 \4\3 \4\3\2\0\n"
} else {
assure "\0\1\2\3\4 \0\0\0\1\2\3\4 \0\4 \3\4 \0\2\3\4 \0\1\2\3\4 \4\3\2\1\0 \4\3\2\1\0\0\0 \4\0 \4\3 \4\3\2\0\n"
}
put DZ:sbcd -1020304
if {$tcl_platform(machine) == "x86_64"} {
assure "\xf0\0\0\0\0\1\2\3\4 \xf0\0\0\0\0\1\2\3\4 \xf0\4 \xf3\4 \xf0\2\3\4 \xf0\1\2\3\4 \4\3\2\1\0\0\0\0\xf0 \4\3\2\1\0\0\0\0\xf0 \4\xf0 \4\xf3 \4\3\2\xf0\n"
} else {
assure "\0\1\2\3\4 \0\0\0\1\2\3\4 \0\4 \3\4 \0\2\3\4 \0\1\2\3\4 \4\3\2\1\0 \4\3\2\1\0\0\0 \4\0 \4\3 \4\3\2\0\n"
}
finish
